package com.stellar.pay.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAPublicKeyConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Author Jqcc
 * @Version 1.0
 * @Data 2025/4/5
 * @Description : 自动装配JsapiServiceExtension
 */
@Configuration
public class JsapiserviceExtensionConfig {

    @Resource
    private WxPayConfig wxPayConfig;

    @Bean
    public JsapiServiceExtension jsapiServiceExtension() {
        // 配置商户相关信息
        Config config = new RSAPublicKeyConfig.Builder()
                .merchantId(wxPayConfig.getMchId())
                .privateKeyFromPath(wxPayConfig.getMchPrivateKeyPath())
                .publicKeyFromPath(wxPayConfig.getWxPublicKeyPath())
                .publicKeyId(wxPayConfig.getWxPublicKeyId())
                .merchantSerialNumber(wxPayConfig.getMchSerialNumber())
                .apiV3Key(wxPayConfig.getApiV3Key())
                .build();

        // 创建服务
        JsapiServiceExtension jsapiService = new JsapiServiceExtension.Builder().config(config).build();
        return jsapiService;
    }

}
